home *** CD-ROM | disk | FTP | other *** search
/ Apple II Magazines (PO) / Nibble Volume 11, No. 01 (1990-01)(MindCraft Publishing)(Side A).zip / Nibble Volume 11, No. 01 (1990-01)(MindCraft Publishing)(Side A).po / FILE.READ.ASM.txt < prev    next >
Text File  |  1996-12-24  |  18KB  |  466 lines

  1. ****************************************
  2. *                                      *
  3. *     FILE.READ.ASM Source Listing     *
  4. *          by  Sandy Mossberg          *
  5. *                                      *
  6. *            APW Assembler             *
  7. *                                      *
  8. *          Copyright (C) 1989          *
  9. *       by MindCraft Publ. Corp.       *
  10. *          Concord, MA  01742          *
  11. *                                      *
  12. ****************************************
  13.             mcopy    file.read.mac
  14.             keep     file.read
  15.  
  16. DPHndl      gequ     $00             ;handle to direct page space
  17. DPPtr       gequ     $04             ;ptr to direct page space
  18. DataBufHndl gequ     $08             ;handle to data buffer for file contents
  19. DataBufPtr  gequ     $0C             ;ptr to data buffer for file contents
  20. PrtRecHndl  gequ     $10             ;handle to print record
  21. PrtRecPtr   gequ     $14             ;ptr to print record
  22. ScreenMode  gequ     $80             ;640x200 super hi-res ($00 = 320x200)
  23. ScreenWidth gequ     640             ;640 pixel screen width
  24.  
  25. top         gequ     0               ;offsets in coordinate fields
  26. left        gequ     2
  27. bottom      gequ     4
  28. right       gequ     6
  29.  
  30. v           gequ     0               ;offsets in pen position fields
  31. h           gequ     2
  32.  
  33. *****************************************************************
  34. *
  35. MainLoop    start
  36. *
  37. * Main program loop:
  38. *
  39. *****************************************************************
  40.             using    GlobalData
  41.  
  42.             phk                      ;equate program bank
  43.             plb                      ; with data bank
  44.             jsr      StartUp         ;startup tool sets
  45.             bcs      Quit            ;boot disk not online
  46.             jsr      InitDesktop     ;initialize desktop
  47.             jsr      InitApplic      ;initialize application
  48.             jsr      EventLoop       ;scan for events
  49.             jsr      ShutApplic      ;free program memory
  50.             jsr      ShutDown        ;shutdown tool sets
  51. Quit        _QuitGS  QuitParm        ;quit to calling application
  52. ;................................................................
  53. ;
  54. ; MainLoop data:
  55. ;
  56. QuitParm    anop                     ;Quit parmlist (GS/OS class 1)
  57.             dc       i2'0'           ;pCount = 0 (input)
  58.             end
  59.  
  60. *****************************************************************
  61. *
  62. InitDesktop start
  63. *
  64. * Initialize desktop:
  65. *
  66. *****************************************************************
  67.  
  68.             PushLong #0              ;refresh entire desktop
  69.             _RefreshDesktop
  70.  
  71.             ldx      #MTIndex        ;get index to last entry in menu table
  72. MenuLoop    phx                      ;save index to menu table
  73.             PushLong #0              ;space for result
  74.             lda      MenuTable+2,x   ;ptr hi to menu template
  75.             pha                      ; (menu lines and item lines)
  76.             lda      MenuTable,x     ;ptr lo to menu template
  77.             pha                      ; (menu lines and item lines)
  78.             _NewMenu                 ;create new menu in system menu bar
  79.             PushWord #0              ;insert menu in front of other menus
  80.             _InsertMenu              ;insert specified menu in menu list
  81.             plx                      ;retrieve index to menu table
  82.             dex                      ;get next entry in menu table
  83.             dex
  84.             dex
  85.             dex
  86.             bpl      MenuLoop        ;loop back for another menu
  87.  
  88.             PushWord #1              ;ID of NDA menu
  89.             _FixAppleMenu            ;setup NDA menu
  90.  
  91.             pha                      ;space for result
  92.             _FixMenuBar              ;set standard size of menu bar
  93.             pla                      ;discard menu height
  94.  
  95.             _DrawMenuBar             ;display system menu bar
  96.             rts
  97. ;................................................................
  98. ;
  99. ; InitDesktop data:
  100. ;
  101. MenuTable   anop                     ;table of ptrs to menu templates below
  102.             dc       i4'AppleMenu'
  103.             dc       i4'FileMenu'
  104.             dc       i4'EditMenu'
  105. MTIndex     equ      *-MenuTable-4   ;index to last entry in table
  106.  
  107. AppleMenu   dc       c'>>@\N1X',h'00'
  108.             dc       c'--About File Reader...\N256',h'00'
  109.             dc       c'---\N300D',h'00'
  110.             dc       c'.'
  111.  
  112. FileMenu    dc       c'>>  File  \N2',h'00'
  113.             dc       c'--Open File...\N257*Oo',h'00'
  114.             dc       c'--Close\N255*WwD',h'00'
  115.             dc       c'---\N300D',h'00'
  116.             dc       c'--Choose Printer...\N258D',h'00'
  117.             dc       c'--Page Setup...\N259D',h'00'
  118.             dc       c'--Print File...\N260*PpD',h'00'
  119.             dc       c'---\N300D',h'00'
  120.             dc       c'--Quit\N261*Qq',h'00'
  121.             dc       c'.'
  122.  
  123. EditMenu    dc       c'>>  Edit  \N3',h'00'
  124.             dc       c'--Undo\N250*ZzD',h'00'
  125.             dc       c'--Cut\N251*XxD',h'00'
  126.             dc       c'--Copy\N252*CcD',h'00'
  127.             dc       c'--Paste\N253*VvD',h'00'
  128.             dc       c'--Clear\N254D',h'00'
  129.             dc       c'.'
  130.             end
  131.  
  132. *****************************************************************
  133. *
  134. InitApplic  start
  135. *
  136. * Initialize application specific data:
  137. *
  138. *****************************************************************
  139.             using    GlobalData
  140.  
  141.             stz      QuitFlag        ;clear quit flag
  142.             stz      PrtRecHndl      ;zero print record handle
  143.             stz      PrtRecHndl+2
  144.             tdc                      ;save application's direct page
  145.             sta      MyDP            ; for window update handler
  146.             rts
  147.             end
  148.  
  149. *****************************************************************
  150. *
  151. EventLoop   start
  152. *
  153. * Handle events:
  154. *
  155. *****************************************************************
  156.             using    GlobalData
  157.  
  158. ; Scan for events with TaskMaster:
  159.  
  160.             pha                      ;space for result
  161.             PushWord #$FFFF          ;handle all events
  162.             PushLong #TaskRecord     ;ptr to extended task record
  163.             _TaskMaster              ;get the event
  164.             pla                      ;get result
  165.  
  166. ; Handle event:
  167.  
  168.             asl      a               ;create index into 2-byte
  169.             tax                      ; entries of task table
  170.             jsr      (TaskTable,x)   ;call event handler
  171.  
  172. ; Check for quit signal:
  173.  
  174.             lda      QuitFlag
  175.             bpl      EventLoop       ;Quit not chosen so keep scanning
  176.             rts
  177. ;................................................................
  178. ;
  179. ; EventLoop data:
  180. ;
  181. TaskTable   anop                     ;GetNextEvent event handlers:
  182.             dc       i2'DoNull'      ; 0 = nullEvt
  183.             dc       i2'DoRTS'       ; 1 = mouseDownEvt
  184.             dc       i2'DoRTS'       ; 2 = mouseUpEvt
  185.             dc       i2'DoRTS'       ; 3 = keyDownEvt
  186.             dc       i2'DoRTS'       ; 4 = undefined
  187.             dc       i2'DoRTS'       ; 5 = autoKeyEvt
  188.             dc       i2'DoRTS'       ; 6 = updateEvt
  189.             dc       i2'DoRTS'       ; 7 = undefined
  190.             dc       i2'DoRTS'       ; 8 = activateEvt
  191.             dc       i2'DoRTS'       ; 9 = switchEvt
  192.             dc       i2'DoRTS'       ;10 = deskAccEvt
  193.             dc       i2'DoRTS'       ;11 = driverEvt
  194.             dc       i2'DoRTS'       ;12 = app1Evt
  195.             dc       i2'DoRTS'       ;13 = app2Evt
  196.             dc       i2'DoRTS'       ;14 = app3Evt
  197.             dc       i2'DoRTS'       ;15 = app4Evt
  198.             anop                     ;TaskMaster event handlers:
  199.             dc       i2'DoRTS'       ;16 = wInDesktop
  200.             dc       i2'DoMenu'      ;17 = wInMenuBar
  201.             dc       i2'DoRTS'       ;18 = wClickCalled
  202.             dc       i2'DoRTS'       ;19 = wInContent
  203.             dc       i2'DoRTS'       ;20 = wInDrag
  204.             dc       i2'DoRTS'       ;21 = wInGrow
  205.             dc       i2'DoClose'     ;22 = wInGoAway
  206.             dc       i2'DoRTS'       ;23 = wInZoom
  207.             dc       i2'DoRTS'       ;24 = wInInfo
  208.             dc       i2'DoMenu'      ;25 = wInSpecial
  209.             dc       i2'DoRTS'       ;26 = wInDeskItem
  210.             dc       i2'DoRTS'       ;27 = wInFrame
  211.             dc       i2'DoRTS'       ;28 = wInactMenu
  212.             dc       i2'DoRTS'       ;29 = wClosedNDA
  213.             dc       i2'DoRTS'       ;30 = wCalledSysEdit
  214.             dc       i2'DoRTS'       ;31 = wTrackZoom
  215.             dc       i2'DoRTS'       ;32 = wHitFrame
  216.             end
  217.  
  218. *****************************************************************
  219. *
  220. DoMenu      start
  221. *
  222. * Handle menu events (menu items must be numbered sequentially):
  223. *
  224. *****************************************************************
  225.             using    GlobalData
  226.  
  227.             sec
  228.             lda      TaskData        ;get menu item ID
  229.             sbc      #250            ;convert N250 into 1st (0th) item
  230.             asl      a               ;create index into 2-byte entries
  231.             tax                      ; of menu item table
  232.             jsr      (ItemTable,x)   ;call menu item handler
  233.  
  234.             PushWord #0              ;TRUE=highlight, FALSE=unhighlight
  235.             PushWord TaskData+2      ;menu ID
  236.             _HiliteMenu              ;unhighlight menu
  237.             rts
  238. ;................................................................
  239. ;
  240. ; DoMenu data:
  241. ;
  242. ItemTable   anop                     ;menu item handlers
  243.             dc       i2'DoRTS'       ;250 = Undo
  244.             dc       i2'DoRTS'       ;251 = Cut
  245.             dc       i2'DoRTS'       ;252 = Copy
  246.             dc       i2'DoRTS'       ;253 = Paste
  247.             dc       i2'DoRTS'       ;254 = Clear
  248.             dc       i2'DoClose'     ;255 = Close
  249.             dc       i2'DoAbout'     ;256 = About...
  250.             dc       i2'DoOpen'      ;257 = Open File
  251.             dc       i2'DoChooser'   ;258 = Choose Printer...
  252.             dc       i2'DoSetup'     ;259 = Page Setup...
  253.             dc       i2'DoPrint'     ;260 = Print File...
  254.             dc       i2'DoQuit'      ;261 = Quit
  255.             end
  256.  
  257. *****************************************************************
  258. *
  259. ShutApplic  start
  260. *
  261. * Deallocate memory before shutting down tool sets:
  262. *
  263. *****************************************************************
  264.             using    GlobalData
  265.  
  266.             jsr      DoClose         ;close front window, if open
  267.  
  268.             lda      FrontWinPtr     ;check for open window
  269.             ora      FrontWinPtr+2
  270.             bne      ShutApplic      ;another window open
  271.  
  272.             PushLong PrtRecHndl      ;handle to print record
  273.             _DisposeHandle           ;deallocate print record space
  274.             rts
  275.             end
  276.  
  277. *****************************************************************
  278. *
  279. DoRTS       start
  280. *
  281. * Ignore an event:
  282. *
  283. *****************************************************************
  284.  
  285.             rts
  286.             end
  287.  
  288. *****************************************************************
  289. *
  290. DoQuit      start
  291. *
  292. * Turn on quit flag to terminate this application:
  293. *
  294. *****************************************************************
  295.             using    GlobalData
  296.  
  297.             lda      #$8000
  298.             sta      QuitFlag        ;set quit flag
  299.             rts
  300.             end
  301.  
  302. *****************************************************************
  303. *
  304. DoNull      start
  305. *
  306. * Enable or disable menu items during null events:
  307. *
  308. *****************************************************************
  309.             using    GlobalData
  310.  
  311.             PushLong #0              ;space for result
  312.             _FrontWindow             ;get ptr to front window
  313.             PullLong FrontWinPtr     ;save ptr
  314.  
  315.             anop                     ;stack menu items:
  316.             PushWord #250            ;Undo
  317.             PushWord #251            ;Cut
  318.             PushWord #252            ;Copy
  319.             PushWord #253            ;Paste
  320.             PushWord #254            ;Clear
  321.             PushWord #255            ;Close
  322.             PushWord #258            ;Choose Printer...
  323.             PushWord #259            ;Page Setup...
  324.             PushWord #260            ;Print File...
  325.  
  326.             lda      FrontWinPtr     ;check for open window
  327.             ora      FrontWinPtr+2
  328.             beq      NoWind          ;no window open
  329.  
  330.             pha                      ;space for result
  331.             PushLong FrontWinPtr     ;ptr to front window
  332.             _GetWKind                ;get window type
  333.             pla                      ;PL = application, MI = system
  334.             bpl      ApplicWind
  335.  
  336.             anop                     ;NDA window in front
  337.             _DisableMItem            ;dim print items
  338.             _DisableMItem
  339.             _DisableMItem
  340.             _EnableMItem             ;hilite special items
  341.             _EnableMItem
  342.             _EnableMItem
  343.             _EnableMItem
  344.             _EnableMItem
  345.             _EnableMItem
  346.             rts
  347.  
  348. ApplicWind  anop                     ;application window in front
  349.             _EnableMItem             ;hilite print items
  350.             _EnableMItem
  351.             _EnableMItem
  352.             _EnableMItem             ;hilite Close item
  353.             bra      DimEdit         ;dim Edit menu items
  354.  
  355. NoWind      anop                     ;no window open
  356.             _DisableMItem            ;dim print items and special items
  357.             _DisableMItem
  358.             _DisableMItem
  359.             _DisableMItem
  360. DimEdit     _DisableMItem
  361.             _DisableMItem
  362.             _DisableMItem
  363.             _DisableMItem
  364.             _DisableMItem
  365.             rts
  366.             end
  367.  
  368. *****************************************************************
  369. *
  370. DoClose     start
  371. *
  372. * Close front window:
  373. *
  374. *****************************************************************
  375.             using    GlobalData
  376.  
  377.             PushLong #0              ;space for result
  378.             _FrontWindow             ;get ptr to front window
  379.             PullLong FrontWinPtr     ;save ptr
  380.  
  381.             lda      FrontWinPtr     ;check for open window
  382.             ora      FrontWinPtr+2
  383.             beq      Done            ;no window open
  384.  
  385.             PushLong FrontWinPtr     ;ptr to front window
  386.             _CloseNDAbyWinPtr        ;close NDA window
  387.             bcc      Done            ;NDA window closed
  388.  
  389.             PushLong DataBufHndl     ;handle to file data buffer
  390.             _DisposeHandle           ;deallocate handle and free memory
  391.             jsr      HandlErr
  392.  
  393.             PushWord #257            ;enable Open File item
  394.             _EnableMItem
  395.  
  396.             PushLong FrontWinPtr     ;ptr to front window
  397.             _CloseWindow             ;close application window
  398.  
  399. Done        rts
  400.             end
  401.  
  402. *****************************************************************
  403. *
  404. DoAbout     start
  405. *
  406. * Handle About item in Apple menu (display title and credits):
  407. *
  408. *****************************************************************
  409.  
  410.             pha                      ;space for result
  411.             PushWord #0              ;C-string
  412.             PushLong #0              ;no substitution array
  413.             PushLong #AlertStr       ;ptr to alert string
  414.             _AlertWindow             ;display alert window
  415.             pla                      ;discard button ID (always OK button)
  416.             rts
  417. ;................................................................
  418. ;
  419. ; DoAbout data:
  420.  
  421. AlertStr    anop                                       ;alert string
  422.             dc       c'0',i'50,160,125,480'            ;coordinates
  423.             dc       c'0/'                             ;no icon, separator
  424.             dc       h'01',c'J',i'1'                   ;center text
  425.             dc       h'01',c'S',i'1'                   ;bold text
  426.             dc       h'0D',c'Ascii File Reader',2h'0D' ;title
  427.             dc       h'01',c'S',i'0'                   ;standard text
  428.             dc       c'by Sandy Mossberg',h'0D'        ;credits
  429.             dc       c'(c)1989 by MindCraft Publ. Corp.'
  430.             dc       c'/^#0'                           ;separator, OK default
  431.             dc       h'00'                             ;zero terminator
  432.             end
  433.  
  434. *****************************************************************
  435. *
  436. GlobalData  data
  437. *
  438. * Global program data:
  439. *
  440. *****************************************************************
  441.  
  442. MasterID    ds       2               ;master memory ID of application
  443. MyDP        ds       2               ;direct page of application
  444. QuitFlag    ds       2               ;quit flag
  445. FrontWinPtr ds       4               ;ptr to front window
  446. PenLoc      ds       4               ;coordinates of pen position
  447. LeftEdge    ds       2               ;left margin of page
  448.  
  449. TaskRecord  anop                     ;extended event record for TaskMaster
  450. What        ds       2               ;event code
  451. Message     ds       4               ;event message
  452. When        ds       4               ;ticks since startup
  453. Where       ds       4               ;global position of mouse
  454. Modifiers   ds       2               ;state of modifier keys
  455. TaskData    ds       4               ;extended event data
  456. TaskMask    dc       i4'$FFFF'       ;bit flag (ignore no functions)
  457.  
  458. EOFParm     anop                     ;GetEOF parmlist (GS/OS class 1)
  459.             dc       i2'2'           ;pCount = 2 (input)
  460. EOFRefNum   ds       2               ;reference number (input)
  461. EOF         ds       4               ;size of file in bytes (result)
  462.             end
  463.  
  464.             copy     basics.asm
  465.             copy     fr.options.asm
  466.